Skip to content

Hw2 voskoboinikov #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Conversation

wwoskie
Copy link

@wwoskie wwoskie commented Sep 16, 2023

Team HW2 on python BI 2023/2024

Copy link

@albidgy albidgy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отличная работа!

  • README понятный, приведены примеры. Только лучше писать README на английском языке.
  • Комментарии к коммитам отличные.
  • Хорошие, осознанные названия переменных и функций.
  • Здорово, что сделали реализацию с while.

Баллы:
За каждую функцию: 1.6 * 5 = 8 баллов
За README 1 + 1 доп. = 2 балла
За наличие всех форков и пулл-реквестов - 1 балл
Дополнительные баллы за pattern matching - 0.2 и 0.1 за while = 0.3 балла.

Итого: 11.3 балла

@@ -0,0 +1,35 @@
def addition(a, b):
return(a + b)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

скобки у return не нужны

Suggested change
return(a + b)
return a + b

@@ -0,0 +1,35 @@
def addition(a, b):
return(a + b)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

По PEP8 после функции делают 2 пропуска строки

return(a + b)

def subtraction(a, b):
return(a - b)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return(a - b)
return a - b

return(a - b)

def multiplication(a, b):
return(a * b)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return(a * b)
return a * b

return(a * b)

def division(a, b):
return(a / b)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return(a / b)
return a / b

Comment on lines +19 to +22
calculator_func_dict = {'-': subtraction,
'*': multiplication,
'+': addition,
'/': division}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


calc_string = input('Enter your expression: ')

while calc_string != 'exit':
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здорово, что сделали возможность проводить столько вычислений, сколько нужно пользователю👍

calc_string = input('Enter your expression: ')

while calc_string != 'exit':
command = calc_parser(calc_string)[1]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно один раз вызвать функцию calc_parser() и потом разом записать в переменные элементы в список, а не трижды ее вызывать. Так работает, но выглядит неоптимально.
Например:

Suggested change
command = calc_parser(calc_string)[1]
numb1, command, numb2 = calc_parser(calc_string)

Comment on lines +24 to +35
calc_string = input('Enter your expression: ')

while calc_string != 'exit':
command = calc_parser(calc_string)[1]
if command in calculator_func_dict:
print(calculator_func_dict[command](calc_parser(calc_string)[0], calc_parser(calc_string)[2]))
else:
print('Seems like an invalid expression. Please, enter valid expression!')

calc_string = input('Enter your expression: ')

print('See you next time!')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот код тоже можно было обернуть в функцию

Suggested change
calc_string = input('Enter your expression: ')
while calc_string != 'exit':
command = calc_parser(calc_string)[1]
if command in calculator_func_dict:
print(calculator_func_dict[command](calc_parser(calc_string)[0], calc_parser(calc_string)[2]))
else:
print('Seems like an invalid expression. Please, enter valid expression!')
calc_string = input('Enter your expression: ')
print('See you next time!')
def main():
calc_string = input('Enter your expression: ')
while calc_string != 'exit':
command = calc_parser(calc_string)[1]
if command in calculator_func_dict:
print(calculator_func_dict[command](calc_parser(calc_string)[0], calc_parser(calc_string)[2]))
else:
print('Seems like an invalid expression. Please, enter valid expression!')
calc_string = input('Enter your expression: ')
print('See you next time!')
main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants